package com.jdz.gxq.info.admin.fund.service;

import java.util.List;
import java.util.Map;

import jp.terasoluna.fw.dao.QueryDAO;
import jp.terasoluna.fw.dao.UpdateDAO;

import com.jdz.gxq.info.admin.fund.bo.Fund;

public class FundServiceImpl implements FundService {

	private QueryDAO queryDAO = null;

	private UpdateDAO updateDAO = null;

	/**
	 * Fund检索分页用，查询记录条数
	 * 
	 * @return
	 */
	public int getFundsCount(String enterpriseName) {

		int totalCount = queryDAO.executeForObject("fund.getFundsCount",
				enterpriseName, Integer.class);

		return totalCount;
	}

	/**
	 * Fund检索
	 * 
	 * @return
	 */
	public List<Fund> getFunds(Map<String, Object> params) {

		return queryDAO.executeForObjectList("fund.getFunds", params);
	}

	/**
	 * 追加Fund
	 * 
	 * @param fund
	 */
	public void insertFund(Fund fund) {

		updateDAO.execute("fund.insertFund", fund);
	}

	/**
	 * 更新Fund
	 * 
	 * @param fund
	 */
	public void updateFund(Fund fund) {

		updateDAO.execute("fund.updateFund", fund);
	}

	/**
	 * 通过id得到fund
	 * 
	 * @param id
	 * @return
	 */
	public Fund getFundById(int id) {

		Fund fund = queryDAO.executeForObject("fund.getFundById", id,
				Fund.class);

		return fund;
	}

	/**
	 * 删除Fund
	 * 
	 * @param fund
	 */
	public void deleteFund(int id) {

		updateDAO.execute("fund.deleteFundById", id);
	}

	/**
	 * 验证fundName是否重复 flag: 1 追加时验证 flag: 2 更新时验证
	 */
	public boolean checkFundName(Fund paramFund, int flag) {

		Fund fund = queryDAO.executeForObject("fund.getFundByName",
				paramFund.getProjectName(), Fund.class);

		if (fund == null) {
			return true;
		}

		// 更新验证，查出来的数据是不是本身
		if (flag == 2) {

			if (fund.getId() == paramFund.getId()) {
				return true;
			}
		}

		return false;
	}

	public void setQueryDAO(QueryDAO queryDAO) {
		this.queryDAO = queryDAO;
	}

	public void setUpdateDAO(UpdateDAO updateDAO) {
		this.updateDAO = updateDAO;
	}

}
